#include "StdAfx.h"
#include ".\mfcwpfline.h"

CMFCWPFLine::CMFCWPFLine(void)
{
	X1 = 0;
	Y1 = 0;
	X2 = 0;
	Y2 = 0;
}

CMFCWPFLine::~CMFCWPFLine(void)
{
}

///<summary>
///Get Node Attributes from the xaml file using the path and
///calculate the line's start and end point
///</summary>
///<param name='szPath'>
///the path in the xaml file
///</param>
///<param name='pXmlParser'>
///the pointer to the xml parser
///</param>
///<param name='oRect'>
///the region of the element that contains this element
///</param>
void CMFCWPFLine::Parse(const CString & szPath, CECGXmlParser * pXamlParser, const CRect & oRect)
{
	CMFCWPFElement::Parse(szPath, pXamlParser, oRect);
	CalculatePoint(oRect);
}

///<summary>
///Draw the line in the context of pCDCPlus 
///according to the "IsEnabled" attribute
///</summary>
///<param name='pCDCPlus'>
///the pointer to the GDI+ display context
///</param>
///<returns>
///true if the element is enabled; false otherwise
///</returns>
bool CMFCWPFLine::DrawSelf(CDCPlus * pCDCPlus)
{
	if (CMFCWPFElement::DrawSelf(pCDCPlus))
	{
		CPenLib::PEN_PROPERTIES sPenPro;
		int nValue = 0;
		m_oAttributes.GetAttribute(_ATTRIBUTESTROKEDASHARRAY0, nValue);
		sPenPro.arrDashPattern[0] = (float)nValue;
		m_oAttributes.GetAttribute(_ATTRIBUTESTROKEDASHARRAY1, nValue);
		sPenPro.arrDashPattern[1] = (float)nValue;
		m_oAttributes.GetAttribute(_ATTRIBUTESTROKEDASHCOUNT, nValue);
		sPenPro.nDashPatternCount = nValue;
		m_oAttributes.GetAttribute(_ATTRIBUTESTROKETHICKNESS, nValue);
		sPenPro.nFlag = 1;
		CString szColorName;
		m_oAttributes.GetAttribute(_ATTRIBUTESTROKE, szColorName);
		pCDCPlus->SetPenPlus(m_oAttributes.GetColorFromName(szColorName), (float)nValue, sPenPro);
		pCDCPlus->MoveToPlus(X1, Y1);
		pCDCPlus->LineToPlus(X2, Y2);
		return true;
	}
	return false;
}

///<summary>
///Calculate the line's start and end point
///</summary>
///<param name='oRect'>
///the region of the element that contains this line
///</param>
void CMFCWPFLine::CalculatePoint(const CRect & oRect)
{
	int nTopLeftX = 0;
	int nTopLeftY = 0;
	int nBottomRightX = 0;
	int nBottomRightY = 0;
	m_oAttributes.GetAttribute(_ATTRIBUTEX1, nTopLeftX);
	m_oAttributes.GetAttribute(_ATTRIBUTEY1, nTopLeftY);
	m_oAttributes.GetAttribute(_ATTRIBUTEX2, nBottomRightX);
	m_oAttributes.GetAttribute(_ATTRIBUTEY2, nBottomRightY);
	X1 = oRect.left+nTopLeftX;
	Y1 = oRect.top+nTopLeftY;
	X2 = oRect.left+nBottomRightX;
	Y2 = oRect.top+nBottomRightY;
}